#ifndef CNETWORK_H
#define CNETWORK_H

#include <QApplication>
#include "crequestget.h"
#include "cnetworkconfig.h"
#include "connectivityhelper.h"
#include <QNetworkSession>
#include "cexplainfactory.h"

// CDoBusiness is the abstract class used to do the core business after
// get the network communication result

class CNetwork : public QObject
{
    Q_OBJECT

public:
    CNetwork(QObject *parent = 0);
    ~CNetwork();

public:
    bool initialize();

public Q_SLOTS:
    //the following slots should be associated with some clicked buttons
    bool openSession();

    bool closeSession();

    void request(int command, QString ipAddress, QString *arg, int count);

protected:
    QMultiMap<QString, QString> * getResult(){ return m_pResult; }

signals:
    void downloadProgressSignal(qint64 bytesReceived, qint64 bytesTotal);
    void downloadFinishedSignal();


protected Q_SLOTS:
    //the following slots should be associated with download actions
    virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);

    //if you want to override these slots, please call them
    //at the beginning of your function
    virtual void downloadFinished();

    void downloadError(QNetworkReply::NetworkError code);

protected:
    virtual void dealError();


private:
    CNetworkConfig      *m_pConfig;

    QNetworkSession     *m_pSession;

    ConnectivityHelper  *m_pConnectivityHelper;

    CExplainFactory     *m_pExplainFactor;

    CRequestGet         *m_pRequestGet;

    QMultiMap<QString, QString> *m_pResult;

    bool                 m_bShuttingDown;
};

#endif // CNETWORK_H
